/**
 * Created with CLion.
 * Description: 
 * User: loong
 * Date: 2024/6/6
 * Time: 16:31
 */
#include <QPainter>

#include "CardUi.h"
#include "Game.h"
#include "GameUi.h"
#include "OverlapLayout.h"
#include "TrumpSelect.h"
using namespace std;

#define ARole Player::UserGroup + 1
#define BRole Player::UserGroup + 2

using namespace Upgrade;
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    GameSPtr     game = make_shared<Game>(4, 2, 8);

    auto playerA1 = make_shared<Player>("PlayerA1", static_cast<Player::GroupId>(ARole));
    auto playerB1 = make_shared<Player>("PlayerB1", static_cast<Player::GroupId>(BRole));
    auto playerA2 = make_shared<Player>("PlayerA2", static_cast<Player::GroupId>(ARole));
    auto playerB2 = make_shared<Player>("PlayerB2", static_cast<Player::GroupId>(BRole));

    GameUi uiA1(game, playerA1);
    GameUi uiB1(game, playerB1);
    GameUi uiA2(game, playerA2);
    GameUi uiB2(game, playerB2);
    uiA1.resize(1474,746);
    uiB1.resize(1474,746);
    uiA2.resize(1474,746);
    uiB2.resize(1474,746);

    uiA1.show();
    // uiB1.show();
    // uiA2.show();
    // uiB2.show();

    // uiA1.setWindowTitle("A1");
    // uiB1.setWindowTitle("B1");
    // uiA2.setWindowTitle("A2");
    // uiB2.setWindowTitle("B2");

    // game->SetMainSuit(playerA1, CardSuit::JokerSuit);
    game->Start();

    //test print
    /*playerA1->Print();
    playerB1->Print();
    playerA2->Print();
    playerB2->Print();

    qDebug() << "PocketCard";
    game->PrintPocketCard();*/

    //test TrumpSelect
    /*TrumpSelect select;
    select.resize(580,100);
    auto mate = QMetaEnum::fromType<CardSuit>();
    for(int i = 0; i < mate.keyCount(); ++i) {
        auto suit  = static_cast<CardSuit>(mate.value(i));
        select.SetEnable(suit,false);
    }
    select.show();*/

    // CardUi card_ui1(make_shared<Card>(CardRank::BigJoker, Qt::black, CardSuit::JokerSuit,true));
    // CardUi card_ui2(make_shared<Card>(CardRank::Nine, Qt::red, CardSuit::DiamondsSuit,false));
    // CardUi card_ui3(make_shared<Card>(CardRank::Nine, Qt::red, CardSuit::DiamondsSuit,true));
    // card_ui1.show();
    // card_ui2.show();
    // card_ui3.show();

    // 布局测试
    /*CardUi card_ui1(make_shared<Card>(CardRank::BigJoker, Qt::black, CardSuit::JokerSuit));
    CardUi card_ui2(make_shared<Card>(CardRank::Nine, Qt::red, CardSuit::DiamondsSuit));
    CardUi card_ui3(make_shared<Card>(CardRank::Nine, Qt::red, CardSuit::DiamondsSuit));
    CardUi card_ui4(make_shared<Card>(CardRank::Nine, Qt::red, CardSuit::DiamondsSuit));
    CardUi card_ui5(make_shared<Card>(CardRank::Nine, Qt::red, CardSuit::DiamondsSuit));
    CardUi card_ui6(make_shared<Card>(CardRank::Nine, Qt::red, CardSuit::DiamondsSuit));
    CardUi card_ui7(make_shared<Card>(CardRank::Nine, Qt::red, CardSuit::DiamondsSuit));
    CardUi card_ui8(make_shared<Card>(CardRank::Nine, Qt::red, CardSuit::DiamondsSuit));

    card_ui1.setProperty("OrderProperty", QVariant::fromValue(*card_ui1.Card()));
    card_ui2.setProperty("OrderProperty", QVariant::fromValue(*card_ui2.Card()));
    card_ui3.setProperty("OrderProperty", QVariant::fromValue(*card_ui3.Card()));
    card_ui4.setProperty("OrderProperty", QVariant::fromValue(*card_ui4.Card()));
    card_ui5.setProperty("OrderProperty", QVariant::fromValue(*card_ui5.Card()));
    card_ui6.setProperty("OrderProperty", QVariant::fromValue(*card_ui6.Card()));
    card_ui7.setProperty("OrderProperty", QVariant::fromValue(*card_ui7.Card()));
    card_ui8.setProperty("OrderProperty", QVariant::fromValue(*card_ui8.Card()));
    // card_ui1.show();
    // card_ui2.show();

    // auto pb1 = new TestBtn();
    // auto pb2 = new TestBtn();
    // auto pb3 = new TestBtn();
    // auto pb4 = new TestBtn();
    // auto pb5 = new TestBtn();

    // pb1->setText("Short");
    // pb2->setText("Short");
    // pb3->setText("Short");
    // pb4->setText("Short");
    // pb5->setText("Short");


    // pb1->setProperty("OrderProperty",1);
    // pb2->setProperty("OrderProperty",2);
    // pb3->setProperty("OrderProperty",3);
    // pb4->setProperty("OrderProperty",4);
    // pb5->setProperty("OrderProperty",5);

    // card_ui1.setFixedSize(150,200);
    // card_ui2.setFixedSize(150,200);
    // card_ui3.setFixedSize(150,200);

    auto widget = new QWidget;
    auto layout = new OverlapLayout(widget, 50);
#if 0
    layout->setSortFunction<int>();
    layout->addWidget(pb1);
    layout->addWidget(pb2);
    layout->addWidget(pb3);
    layout->addWidget(pb4);
    layout->addWidget(pb5);
#else

    // layout->setSortFunction<Card>();
    // layout->addWidget(&card_ui1);
    // layout->addWidget(&card_ui2);
    // layout->addWidget(&card_ui3);
    // layout->addWidget(&card_ui4);
    // layout->addWidget(&card_ui5);
    // layout->addWidget(&card_ui6);
    // layout->addWidget(&card_ui7);
    // layout->addWidget(&card_ui8);
#endif

    widget->show();*/

    return a.exec();
}
